#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int f(int i, int j)
{
	if (j == 0)
	{
		return 1;
	}
	if (i == j)
	{
		return 1;
	}
	else
	{
		return f(i - 1, j - 1) + f(i - 1, j);
	}
}
typedef struct QueueNode
{
	int date;
	struct Queue* next;
}QueueNode;

typedef struct Queue
{
	QueueNode* head;
	QueueNode* tail;
}Queue;

void QueueInit(Queue* p)
{
	p->head = NULL;
	p->tail = NULL;
}

void QueuePush(Queue* p, int x)
{
	QueueNode* newnode = (QueueNode*)malloc(sizeof(QueueNode));
	newnode->date = x;
	if (p->head == NULL)
	{
		p->head = newnode;
		p->tail = newnode;
	}
	else
	{
		newnode->next = p->head;
		p->head = newnode;
	}
}

bool QueueEmpty(Queue* p)
{
	return p->head == NULL;
}

int QueueFront(Queue* p)
{
	return p->tail->date;
}

void QueuePop(Queue* p)
{
	QueueNode* cur = p->head;
	while (cur->next != p->tail)
	{
		cur = cur->next;
	}
	free(p->tail);
	cur->next = NULL;
	p->tail = cur;
}
int main()
{
	int i = 0;
	int j = 0;
	int n = 0;
	printf("=====杨辉三角=====\n");
	printf("要打印多少行？\n");
	scanf("%d", &n);
	Queue qp;
	QueueInit(&qp);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j <= i; j++)
		{
			QueuePush(&qp, f(i, j));
		}
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j <n - i; j++)
		{
			printf(" ");
		}
		for (j = 0; j <= i; j++)
		{
			printf("%2d ", QueueFront(&qp));
			QueuePop(&qp);
		}
		printf("\n");
	}
	return 0;
}